package com.limao.DBProvider;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import com.limao.DBDataClass.SyshonoraryDataClass;
import com.limao.DbConnection.DbConnectionManager;
import com.limao.Tool.CacheClass;

public class SyshonoraryProvider {

	private static SyshonoraryProvider instance=null;

	public static SyshonoraryProvider getInstance() {
		if(instance==null)
		{
			instance=new SyshonoraryProvider();
		}
		return instance;
	}
	
	// 初始化
	private SyshonoraryProvider() {

	}
	
	
	public List<SyshonoraryDataClass> loadSysLevel()
	{
		ArrayList<SyshonoraryDataClass> list = new ArrayList<SyshonoraryDataClass>();
		Connection con = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		try {

			con = DbConnectionManager.getConnection();
			pstmt = con.prepareStatement("select * from cd_sys_honorary where state=1");
			rs = pstmt.executeQuery();
			while (rs.next()) {
				SyshonoraryDataClass tmp=new SyshonoraryDataClass();
				tmp.honoraryid=rs.getString("honoraryid");
				tmp.directlyman_min=rs.getString("directlyman_min");
				tmp.indirectlyman_min=rs.getString("indirectlyman_min");
				tmp.about=rs.getString("about");
				list.add(tmp);
			}
		} catch (Exception e) {
			list.clear();
			e.printStackTrace();
		} finally {
			DbConnectionManager.closeConnection(rs, pstmt, con);
		}
		return list;
	}
	


	public SyshonoraryDataClass Load_SysLevelBy_ID(String level) {

		SyshonoraryDataClass tmp = null;
		Connection con = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		try {
			con = DbConnectionManager.getConnection();
			pstmt = con.prepareStatement("select * from cd_sys_honorary where honoraryid=?");
			pstmt.setInt(1, CacheClass.getIntValue(level));
			rs = pstmt.executeQuery();
			if (rs.next()) {
				tmp = new SyshonoraryDataClass();
				tmp.honoraryid=rs.getString("honoraryid");
				tmp.directlyman_min=rs.getString("directlyman_min");
				tmp.indirectlyman_min=rs.getString("indirectlyman_min");
				tmp.about=rs.getString("about");
			}

		} catch (Exception e) {
			tmp = null;
		} finally {
			DbConnectionManager.closeConnection(rs, pstmt, con);
		}
		return tmp;
	}
	
	
}
